package datastructure;

import java.io.FileInputStream;
import java.util.ArrayList;

import compiler.Parser;

public class Apl {
	
	public static void main(String args[]) {
		Grammatica gram = Grammatica.getInstance();
		Parser parser = null;
		try {
			parser = new Parser(new FileInputStream("invoer1.txt"));
		} catch(Exception e) {
			System.out.println("Er ging iets mis... hihi");
		}
		gram.setBnf(parser.parseRoot());
		System.out.printf(gram.toString());
		LL1Checker ll1 = new LL1Checker(gram);
		ll1.defineStarters();
		ll1.defineFollowers();
		
		ll1.checkLL1();
		
		printStarters(gram.getBnf());
		printFollowers(gram.getBnf());
	}
	
	private static void printStarters(ArrayList<Rule> bnf) {
		System.out.println();
		System.out.println("======================");
		System.out.println("=      STARTERS      =");
		System.out.println("======================");
		for(Rule r : bnf) {
			System.out.println("S(" + r.getNonTerminal() + ") = " + r.toStringStarters());
		}
	}
	
	private static void printFollowers(ArrayList<Rule> bnf) {
		System.out.println();
		System.out.println("======================");
		System.out.println("=     FOLLOWERS      =");
		System.out.println("======================");
		for(Rule r : bnf) {
			System.out.println("F(" + r.getNonTerminal() + ") = " + r.toStringFollowers());
		}
	}
}
